﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using Forest.Core.Infrastructure;
using Forest.Cat.Web.Models;
using Forest.Cat.Domain.Entities;
using Forest.Cat.Web.Models.Catalog;
using Forest.Cat.Web.Models.Jobseekers;
using Forest.Cat.Domain.Entities.Resumes;
using Forest.Cat.Web.Models.JobApplication;
using Forest.Cat.Web.Models.JobApplications;

namespace Forest.Cat.Web.Extensions
{
    public static class MappingExtensions
    {

        // WantAd
        public static WantAdModel ToModel(this WantAd entity)
        {
            if (entity == null)
                throw null;

            var model = new WantAdModel()
            {
                Id = entity.Id,
                Text = entity.Text,
                SubText = entity.SubText,
                NavigatorUrl = entity.NavigateUrl,
                TextStyle = entity.TextStyle,
                DatePosted = entity.DatePosted,
                StartDate = entity.StartDate,
                Width = entity.Width,
                ColumnIndex = entity.Height
            };
            return model;
        }

        // Company
        public static CompanyModel ToModel(this Company entity)
        {
            if (entity == null)
                throw null;

            var model = new CompanyModel()
            {
                Id = entity.Id,
                CompanyName = entity.CompanyName,
                //Profile = entity.Profile,
                Overview = entity.Overview,
                Business = entity.Business,
                Address = entity.Address,
                PostalCode = entity.PostalCode,
                Tel = entity.Tel,
                Fax = entity.Fax,
                Email = entity.Email,
                WebSite = entity.WebSite,
                DailySigned = entity.DailySigned
            };
            return model;
        }

        // LoginModel
        public static LoginModel ToModel(this Jobseeker entity)
        {
            if (entity == null)
                throw null;

            var model = new LoginModel()
            {
                FullName = entity.FullName,
            };
            return model;
        }

        public static JobModel ToModel(this Job entity)
        {
            if (entity == null)
                throw null;

            var model = new JobModel()
            {
                Id = entity.Id,
                JobTitle = entity.JobTitle,
                JobDescription = entity.JobDescription
            };
            return model;
        }

        public static JobPostingModel ToModel(this JobPosting entity)
        {
            if (entity == null)
                throw null;
            var model = new JobPostingModel()
            {
                Id = entity.Id,
                StartDate = entity.StartDate,
                Wants = entity.Wants,
                Contact = entity.Contact,
                Email = entity.Email,
                Tel = entity.Tel,
                Fax = entity.Fax,
                EndDate = entity.EndDate
            };
            return model;
        }

        // LoginModel
        public static LinkModel ToModel(this Link entity)
        {
            if (entity == null)
                throw null;

            var model = new LinkModel()
            {
                Id = entity.Id,
                AreaCode = entity.AreaCode,
                Text = entity.Text,
                TextStyle = entity.TextStyle,
                ImageUrl = entity.ImageUrl,
                NavigateUrl = entity.NavigateUrl,
                SortOrder = entity.SortOrder
            };
            return model;
        }

        /// <summary>
        /// ResumeModel
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static ResumeModel ToModel(this Resume entity)
        {
            if (entity == null)
                throw null;

            var model = new ResumeModel()
            {
                Id = entity.Id,
                DesiredJobTypes = Convert.ToString(entity.DesiredJobType),
                PrivacyStatus = entity.PrivacyStatus,
                ResumeName = entity.ResumeName,
                Notes = entity.Notes,
            };
            return model;
        }

        /// <summary>
        /// ApplicationModel
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static ApplicationModel ToModel(this Application entity)
        {
            if (entity == null)
                throw null;

            var model = new ApplicationModel()
            {
                Id = entity.Id,
                JobPositionId = entity.JobPositionId,
                CompanyId = entity.CompanyId,
                ResumeId = entity.ResumeId,
                CoverLetter = entity.CoverLetter,
                DesiredSalary = entity.DesiredSalary,
            };
            return model;
        }

        /// <summary>
        /// Application
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static Application ToEntity(this ApplicationModel model)
        {
            if (model == null)
                throw null;

            var entity = new Application()
            {
                Id = model.Id,
                //JobId = model.JobId,
                //JobTitle = model.JobTitle,
                JobPositionId = model.JobPositionId,
                CompanyId = model.CompanyId,
                //CompanyName = model.CompanyName,
                ResumeId = model.ResumeId,
                CoverLetter = model.CoverLetter,
                DesiredSalary = model.DesiredSalary,
            };
            return entity;
        }

        /// <summary>
        /// ResumeModel
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static NewsModel ToModel(this News entity)
        {
            if (entity == null)
                throw null;

            var model = new NewsModel()
            {
                Id = entity.Id,
                PostedOn = entity.PostedOn,
                Title = entity.Title,
                Url = entity.Url
            };
            return model;
        }

        public static JobPositionModel ToModel(this JobPosition entity)
        {
            if (entity == null)
                throw null;

            var model = new JobPositionModel()
            {
                Id = entity.Id,
                JobTitle = entity.JobTitle,
                //JobDescription = entity.JobDescription,
                Responsibilities = entity.Responsibilities,
                Qualifications = entity.Qualifications,
                StartDate = entity.StartDate,
                Reposted = entity.Reposted == null ? entity.StartDate : entity.Reposted,
                Wants = entity.Wants,
                Contact = entity.Contact,
                Email = entity.Email,
                Tel = entity.Tel,
                //Fax = entity.Fax,
                EndDate = entity.EndDate,
                IsOpenSalaryRange = entity.IsOpenSalaryRange,
                Status = entity.Status
            };
            return model;
        }
    }
}